// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "EnvironmentManager.generated.h"

UCLASS()
class ISALONG2_API AEnvironmentManager : public AActor
{
	GENERATED_BODY()

private:
	float _tickTimeRemain=0.0f;
	float _tickTimeEach=2.0f;

	UCurveFloat* _sunLightIstCloudDensity;
	UCurveFloat* _sunLightDayNight;
	UCurveFloat* _sunDistributionExponent;
	UCurveFloat* _moonLightCloudIst;
	UCurveFloat* _eFogDayNight;

	UTexture2D* _cloudDensity;
	FColor* _pixelData;
	int _densityMapWidth;
	int _densityMapHeight;
	int _DaysTime=0;

private:
	void UpdateEnvironmentTick();
	void DayTimeUpdate(float DeltaTime);
	void CloudDensityUpdate();

protected:
	// this two light for display 
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = EnvironmentLight)
	UDirectionalLightComponent* _dayLight;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = EnvironmentLight)
	UDirectionalLightComponent* _nightLight;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = EnvironmentLight)
	USkyLightComponent* _skyLight;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = EnvironmentLight)
	UExponentialHeightFogComponent* _expHightFog;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = EnvironmentLight)
	UStaticMeshComponent* _dynamicSkySphere;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = EnvironmentLight)
	UArrowComponent* _sunRoot;

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DayTime)
	float DayLength = 20;  //

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DayTime)
	float TimeOfDay = 1130; //0-2400

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Cloud)
	float CloudDensity = 1.25;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Cloud)
	float CloudDensityTarget = 3.0; //this value follow the CloudDensity when BeginPlay
	
public:	
	// Sets default values for this actor's properties
	AEnvironmentManager();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

};
